import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JPanel;
import weerapp.meet.Meetgegevens;

@SuppressWarnings("serial")
public class MaandView extends JPanel
{
	private MaandPanel maandPanel;
	private ComboPanel comboPanel;
	private Meetgegevens meetgegevens;
	private ComboListener comboListener;
	
	public MaandView()
	{
		meetgegevens = new Meetgegevens("Data/twente.txt");
		setLayout(new BorderLayout());
		maandPanel = new MaandPanel(meetgegevens);
		comboPanel = new ComboPanel();
		
		comboListener = new ComboListener();
		comboPanel.comboJaar.addActionListener(comboListener);
		comboPanel.comboMaand.addActionListener(comboListener);
		
		add(comboPanel, BorderLayout.NORTH);
		add(maandPanel, BorderLayout.CENTER);
		
		maandPanel.setPanel(comboPanel.intMaand, comboPanel.intJaar);
	}
	
	public void Sync(int aMaand,int aJaar){
		comboPanel.intMaand = aMaand;
		comboPanel.intJaar = aJaar;
		comboPanel.comboJaar.setSelectedItem(Integer.toString(aJaar));
		comboPanel.comboMaand.setSelectedIndex(aMaand-1);
	}
	
	public int getMaand(){
		return comboPanel.intMaand;
	}
	
	public int getJaar(){
		return comboPanel.intJaar;
	}
	
	class ComboListener implements ActionListener
	{
		public void actionPerformed(ActionEvent e) 
		{
			if(e.getSource() == comboPanel.comboJaar)
			{
				comboPanel.intJaar = comboPanel.comboJaar.getSelectedIndex() + 2001;
			}
			if(e.getSource() == comboPanel.comboMaand)
			{
				comboPanel.intMaand = comboPanel.comboMaand.getSelectedIndex() + 1;
			}
			maandPanel.setPanel(comboPanel.intMaand, comboPanel.intJaar);
		}
	}
}



